﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using PlanetenGravity.ScreenSystem;
//GUI
using TomShane.Neoforce.Controls;
using TomShane.Neoforce.Importers;

namespace PlanetenGravity
{
    public class OptionsMenu : IGameScreen
    {
        Manager manager;
        Window mainOptionsWindow;

        ListBox resolutionChoose;
        Button applyButton;

        GraphicsDeviceManager graphics;

        public Game1 MainGame { get; set; }

        public OptionsMenu(Game1 game, GraphicsDeviceManager graphics)
        {
            MainGame = game;
            this.graphics = graphics;
            this.manager = Game1.Manager;
        }

        public void Initialize(GraphicsDeviceManager graphics, ContentManager content)
        {
            mainOptionsWindow = new Window(manager);
            mainOptionsWindow.Init();
            mainOptionsWindow.Text = "Optionen";
            mainOptionsWindow.Width = 200;
            mainOptionsWindow.Height = 300;
            mainOptionsWindow.Center();
            mainOptionsWindow.Visible = true;

            resolutionChoose = new ListBox(manager);
            resolutionChoose.Init();
            resolutionChoose.Items.Add("1024*768");
            resolutionChoose.Items.Add("1280*1024");
            resolutionChoose.Left = mainOptionsWindow.Width / 2 - resolutionChoose.Width / 2;
            resolutionChoose.Top = 10;
            resolutionChoose.Width = 100;
            resolutionChoose.Parent = mainOptionsWindow;

            applyButton = new Button(manager);
            applyButton.Init();
            applyButton.Text = "Apply";
            applyButton.Left = mainOptionsWindow.Width / 2 - applyButton.Width / 2;
            applyButton.Top = 70;
            applyButton.Width = 100;
            applyButton.Click += new MouseEventHandler(applyButton_Click);
            applyButton.Parent = mainOptionsWindow;

            manager.Add(mainOptionsWindow);
        }

        void applyButton_Click(object sender, MouseEventArgs e)
        {
            if (resolutionChoose.Items[resolutionChoose.ItemIndex].ToString() == "1024*768")
            {
                graphics.PreferredBackBufferWidth = 1024;
                graphics.PreferredBackBufferHeight = 768;
            }
            else
            {
                graphics.PreferredBackBufferWidth = 1280;
                graphics.PreferredBackBufferHeight = 1024;
            }
            graphics.ApplyChanges();
            MainGame.SwitchGameScreen(MainGame.mainMenu);
        }

        public void UnloadContent()
        {
            mainOptionsWindow.Dispose();
            mainOptionsWindow = null;
        }

        public void Update(GameTime gameTime)
        {
            manager.Update(gameTime);
        }

        public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            manager.Draw(gameTime);
        }
    }
}